﻿using System;
namespace ManagedService
{
    /// <summary>
    /// This interface describes functionality which have to be provided by a managed service.
    /// </summary>
    public interface IServiceApplication
    {
        /// <summary>
        /// Checks, if a specified message is registered
        /// </summary>
        /// <param name="messageToCheck">Message to be checked</param>
        /// <returns>True, if message is already registered</returns>
        bool IsMessageRegistered(int messageToCheck);
        /// <summary>
        /// Checks, if a Service has already been registered
        /// </summary>
        /// <returns>true, if a Service is already registered</returns>
        bool IsServiceRegistered();
        /// <summary>
        /// Raises the RegisteredMessageReceived event.
        /// </summary>
        event ServiceApplication.RegisteredMessageReceivedEventHandler OnRegisteredMessage;
        /// <summary>
        /// Raises the ServiceExiting event.
        /// </summary>
        event ServiceApplication.ServiceExitingEventHandler OnServiceExiting;
        /// <summary>
        /// Raises the ServiceStateChanged event.
        /// </summary>
        event ServiceApplication.ServiceStateChangedEventHandler OnServiceStateChanged;
        /// <summary>
        /// Informs Service to quit. It fires the OnServiceExiting-Event, which uses the CancelEventsArgs as a parameter. By that an exit can be prevented by code.
        /// </summary>
        void Quit();
        /// <summary>
        /// Register windows message
        /// </summary>
        /// <param name="messageToRegister">Message to be registered</param>
        /// <returns>False if message is already registered</returns>
        bool RegisterMessage(int messageToRegister);
        /// <summary>
        /// Registers a Service within the Registry.
        /// The root will be created under HKLM\Software\ManagedServices, if not already created.
        /// Each registered service will have a subkey, which is the ServiceGuid.
        /// </summary>
        void RegisterService();
        /// <summary>
        /// Informs Service to resume
        /// </summary>
        void Resume();
        /// <summary>
        /// Gets the ServiceGuid for the current service.
        /// This GUID is the main key for a service and MUST be unique
        /// </summary>
        Guid ServiceGuid { get; }
        /// <summary>
        /// Gets or sets name of the ServiceApplication
        /// </summary>
        string ServiceName { get; set; }
        /// <summary>
        /// Gets or sets the start type for the current service.
        /// If set to Automatic and ManagedServiceLauncher is installed, services get started by ManagedServiceLauncher during system startup
        /// </summary>
        ServiceStartType ServiceStartType { get; set; }
        /// <summary>
        /// Gets the current state of the running Service
        /// </summary>
        ServiceState ServiceState { get; }
        /// <summary>
        /// Informs Service to stop. Only useful, if Service was stopped or suspended.
        /// </summary>
        void Start();
        /// <summary>
        /// Informs Service to suspend
        /// </summary>
        void Suspend();
        /// <summary>
        /// Unregister windows message
        /// </summary>
        /// <param name="messageToUnregister">Mesage to be unregistered</param>
        /// <returns>True, if message was unregistered successfully</returns>
        bool UnregisterMessage(int messageToUnregister);
        /// <summary>
        /// Unregisters a Service from the Registry, if previously registered.
        /// </summary>
        void UnRegisterService();
    }
}
